package org.fnzn.config;

import org.apache.log4j.Logger;
import org.fnzn.core.Result;
import org.fnzn.exception.MyException;
import org.fnzn.util.ResultGenerator;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 * @author lenovo
 *
 */
@RestControllerAdvice 
public class GlobalExceptionHandler {
	private Logger log=Logger.getLogger(GlobalExceptionHandler.class); 
	@ExceptionHandler(value = { MyException.class })
	public Result MyErrorHandler(MyException e) {
		log.error(e.getMessage());
		return ResultGenerator.genFailResult(e.getMessage());
	}
	@ExceptionHandler(value = { RuntimeException.class })
	public Result defaultErrorHandler(Exception e) {
		e.printStackTrace();
		log.error(e.getMessage(),e);
		return ResultGenerator.genFailResult("操作失败");
	}

}
